<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MakerActivity extends Model
{
    protected $table = 'maker_activity';
    protected $guarded = [''];


    public function Maker(){
        return $this->belongsTo('App\Models\Maker','maker_id','id');
    }

    protected function getDateFormat()
    {
        return 'U';
    }

    //通过maker_id获取activity_id
    static function getActivityByMakerid($maker_id){
    	$result = self::where('maker_id',$maker_id)->lists('activity_id')->toArray();
    	return $result;
    }
    //通过activity_id获取maker_id
    static function getMakerByActivityid($activity_id){
        $result = self::where('activity_id',$activity_id)->lists('maker_id')->toArray();
        return $result;
    }
    //获得活动主办的创客空间
    static function getSponsor($activity_id){
		$result = self::where('activity_id',$activity_id)->where('type','organizer')->first();
    	return $result;
    }
    //获得活动响应的创客空间maker_id
    static function getAssistanceid($activity_id){
    	$result = self::where('activity_id',$activity_id)->where('type','assistance')->lists('maker_id')->toArray();
    	return $result;
    }
    //获取召集跨域活动的活动ID
    static function getOrganizerMaker($maker_id){
    	$result = self::where('maker_id',$maker_id)->where('type','organizer')->lists('activity_id')->toArray();
    	return $result;
    }
    //获取响应跨域活动的活动ID
    static function getAssistanceMaker($maker_id){
    	$result = self::where('maker_id',$maker_id)->where('type','assistance')->lists('activity_id')->toArray();
    	return $result;
    }
    //获取我的跨域活动申请
    static function getApplyMaker($user_id,$activity_id){
        $maker_id = MakerUser::where('uid',$user_id)->first()->maker_id;
        $result = MakerActivity::where('activity_id',$activity_id)->where('maker_id',$maker_id)->where('type','assistance')->first();
        return $result;
    }
}
